home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / cenvid / floppyid.bat < prev    next >
Encoding:
DOS Batch File  |  1995-04-07  |  3.0 KB  |  103 lines

  1. @echo off
  2. REM *****************************************************************
  3. REM *** FloppyID.bat - Get or set the ID from a floppy and store  ***
  4. REM *** ver.2          in environment variable (if wanted)        ***
  5. REM *****************************************************************
  6.  
  7. CEnviD %0.bat %1 %2 %3 %4 %5 %6 %7 %8 %9
  8. GOTO CENVI_EXIT
  9.  
  10. main(argc,argv)
  11. {
  12.    if ( argc < 2  ||  4 < argc
  13.      || strcmp( (drive=argv[1]) + 1, ":" )
  14.      || !isalpha(drive[0])
  15.      || (4 == argc && stricmp(argv[2],"SET")) ) {
  16.       Instructions();
  17.       return(EXIT_FAILURE);
  18.    }
  19.  
  20.    if ( 4 == argc ) {
  21.       // setting the volume ID
  22.       if ( 2 != sscanf(argv[3],"%X-%X",SerialHigh,SerialLow) ) {
  23.          printf("Unrecognized Volume Serial Number format \"%s\"\n\a",argv[3]);
  24.          return(EXIT_FAILURE);
  25.       }
  26.       SetSerialNum(drive[0],SerialHigh << 16 | SerialLow);
  27.    } else {
  28.       // getting the volume ID
  29.       EVar = ( argc == 3 ) ? argv[2] : NULL ;
  30.       if ( EVar )
  31.          putenv(EVar,NULL);
  32.  
  33.       // get serial number
  34.       SerialNum = GetSerialNum(drive[0]);
  35.       sprintf(SerialString,"%04X-%04X",(SerialNum >> 16) & 0xFFFF,SerialNum & 0xFFFF);
  36.       printf("Serial number: %s\n",SerialString);
  37.  
  38.       if ( EVar )
  39.          putenv(EVar,SerialString);
  40.    }
  41.  
  42.    return(EXIT_SUCCESS);
  43. }
  44.  
  45. Instructions()
  46. {
  47.    printf("\a\n")
  48.    printf("FloppyID - Read disk serial number ID\n")
  49.    printf("\n")
  50.    printf("SYNTAX: FLOPPYID <d>: [EnvVar | SET <id>]\n")
  51.    printf("\n")
  52.    printf("Where: <d> Drive designation (e.g. A:, B:, etc...)\n")
  53.    printf("       EnvVar - Optional environment variable to store ID\n")
  54.    printf("       SET <id> - Set to id in hexadecimal form XXXX-XXXX\n")
  55.    printf("\n")
  56.    printf("Examples: FLOPPYID A:\n")
  57.    printf("          FLOPPYID A: A_SERIAL\n")
  58.    printf("          FLOPPYID A: SET E224-3815\n")
  59.    printf("\n")
  60.    printf("ERRORLEVEL: Sets ERRORLEVEL %d for error, %d if success\n",EXIT_FAILURE,EXIT_SUCCESS)
  61.    printf("\n")
  62. }
  63.  
  64. Function44Subfunction0D(pDriveLetter,pSubFunction,pBuffer)
  65. {
  66.    RegIn.ax = 0x440D;
  67.    RegIn.bx = toupper(pDriveLetter) - 'A' + 1;
  68.    RegIn.ch = 0x08;
  69.    RegIn.cl = pSubFunction;
  70.    RegIn.ds = segment(pBuffer);
  71.    RegIn.dx = offset(pBuffer);
  72.    if ( !interrupt(0x21,RegIn,RegOut) ) {
  73.       printf("\aError %d on interrupt 0x21 subfunction 0x44\n",RegOut.ax);
  74.       exit(EXIT_FAILURE);
  75.    }
  76. }
  77.  
  78. GetSerialNum(pDriveLetter)
  79. {
  80.    BLObSize(MediaBuffer,100);  // no reason not to be big
  81.    BLObPut(MediaBuffer,0,0,UWORD16);
  82.    Function44Subfunction0D(pDriveLetter,0x66,MediaBuffer);
  83.    return( BLObGet(MediaBuffer,2,UWORD32) );
  84. }
  85.  
  86. SetSerialNum(pDriveLetter,pSerialNum)
  87. {
  88.    BLObSize(MediaBuffer,100);  // no reason not to be big
  89.  
  90.    // get old media ID before setting new one
  91.    BLObPut(MediaBuffer,0,0,UWORD16);
  92.    Function44Subfunction0D(pDriveLetter,0x66,MediaBuffer);
  93.  
  94.    // set to new ID
  95.    BLObPut(MediaBuffer,0,0,UWORD16);
  96.    BLObPut(MediaBuffer,2,pSerialNum,UWORD32);
  97.    Function44Subfunction0D(pDriveLetter,0x46,MediaBuffer);
  98. }
  99.  
  100.  
  101.  
  102. :CENVI_EXIT
  103.